package com.itheima.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.itheima.po.Customer;
import com.itheima.service.CustomerService;;
/**
 * 控制器类
 */

public class CustomerController implements Controller{

	@Override
	public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
		// TODO Auto-generated method stub
		//BirdService birdService = new BirdServiceImpl();
	    ApplicationContext act = 
	            new ClassPathXmlApplicationContext("applicationContext.xml");
	    CustomerService customerService = act.getBean(CustomerService.class);  
	    List<Customer> customerlList = customerService.findCustomerAll();
	    
	    // 创建ModelAndView对象
		ModelAndView mav = new ModelAndView();
		
         // 向模型对象中添加数据
		mav.addObject("customerlList", customerlList);
         // 设置逻辑视图名
		mav.setViewName("/WEB-INF/jsp/customer.jsp");
         // 返回ModelAndView对象
		return mav;
	}

}
